package top.z.orm.handle.osql.chain;

import top.z.orm.core.osql.FunctionType;

import static top.z.orm.core.osql.SqlKeyWord.L_PARENTHESIS;
import static top.z.orm.core.osql.SqlKeyWord.R_PARENTHESIS;

/**
 * SQL 聚合函数相关
 */
public class Aggregate {

    public static String max(String field) {
        return selectWithFun(FunctionType.MAX, field);
    }

    public String min(String field) {
        return selectWithFun(FunctionType.MIN, field);
    }

    public String sum(String field) {
        return selectWithFun(FunctionType.SUM, field);
    }

    public String avg(String field) {
        return selectWithFun(FunctionType.AVG, field);
    }

    public String count(String field) {
        return selectWithFun(FunctionType.COUNT, field);
    }

    private static String selectWithFun(FunctionType functionType, String fieldForFun) {
        // eg: sum(price)
        return functionType.getName() + L_PARENTHESIS + fieldForFun + R_PARENTHESIS;
    }
}